﻿#region Copyright information
// 
// Copyright © 2012-2013 Yongkee Cho. All rights reserved.
// 
// This code is a part of the SubnetworkToolkit and governed under the terms of the
// GNU Lesser General  Public License (LGPL) version 2.1 which accompanies this distribution.
// For more information on the LGPL, please visit http://bol.codeplex.com/license.
// 
// - Filename: GeneRelations_Human.cs
// - Author: Yongkee Cho
// - Email: yongkeecho@outlook.com
// - Date Created: 2013-01-30 2:55 PM
// - Last Modified: 2013-01-30 3:21 PM
// 
#endregion
using System;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data.SQLite;

namespace SubnetworkToolkit.Data
{
    [Database]
    public class GeneRelationsHuman : DataContext
    {
        public GeneRelationsHuman()
            : base(new SQLiteConnection("Data Source=Data/GeneRelationsHuman.db;Version=3")) { }

        public Table<RelationDbTypes> RelationDbTypes;
        public Table<RelationDBs> RelationDBs;
        public Table<Relations> Relations;
        public Table<Scores> Scores;
    }

    [Table]
    public class RelationDbTypes
    {
        [Column]
        public int Id { get; set; }
        [Column]
        public string Name { get; set; }
    }

    [Table]
    public class RelationDBs
    {
        [Column]
        public int Id { get; set; }
        [Column]
        public string Name { get; set; }
        [Column]
        public int TypeId { get; set; }
    }

    [Table]
    public class Relations : IEquatable<Relations>
    {
        [Column]
        public int SourceId { get; set; }
        [Column]
        public int TargetId { get; set; }
        [Column]
        public uint Pattern { get; set; }

        #region IEquatable<Relation> implementation

        public bool Equals(Relations other)
        {
            return SourceId.Equals(other.SourceId) && TargetId.Equals(other.TargetId) && Pattern.Equals(other.Pattern);
        }

        #endregion

        #region Object overriden

        public override int GetHashCode()
        {
            return SourceId.GetHashCode() ^ SourceId.GetHashCode() ^ (int)Pattern;
        }

        public override bool Equals(object other)
        {
            if (other == null)
                throw new ArgumentNullException("other");

            if (!(other is Relations))
                throw new InvalidCastException("The 'other' argument is not a Relations object.");
           
            return Equals(other as Relations);
        }

        public override string ToString()
        {
            return String.Format("{0}-{1}", SourceId, TargetId);
        }

        #endregion
    }

    [Table]
    public class Scores
    {
        [Column]
        public uint Pattern { get; set; }
        [Column]
        public double Score { get; set; }
    }
}
